var data={};

$('#navigation').hide();

$(document).ready(function() {
    $('#form').on('submit', function(e) {
        e.preventDefault(); // 阻止表单的默认提交行为

        // 收集表单数据
        var formData = $('#form').serializeArray();
        // 将表单数据转换为对象
        $.each(formData, function(index, field) {
            data[field.name] = field.value;
        });

        $('#navigation').show();
        confirmOrder(data);
    });
});

function confirmOrder(data){
    $.ajax({
        type: 'POST',
        url: 'http://localhost:8080/csu_javaweb_group_assignment_war_exploded/confirmOrderJQuery',
        data: data,
        success: function(response) {
            $('#Catalog').html(response); // 将响应插入到页面的某个容器中
            console.log("confirmOrderForm渲染成功");
        },
        error: function(xhr, status, error) {
            console.error('Error submitting form: ', error);
        }
    });
}

function finalOrder(data){
    $.ajax({
        type: 'POST',
        url: 'http://localhost:8080/csu_javaweb_group_assignment_war_exploded/finalOrderJQuery',
        data: data,
        success: function(response) {
            console.log(response);
            $('#Catalog').html(response); // 将响应插入到页面的某个容器中
            console.log("finalOrderForm渲染成功");
        },
        error: function(xhr, status, error) {
            console.error('Error submitting form: ', error);
        }
    });
}

$('#confirmOrder').on('click',function (){
    confirmOrder(data);
})

$('#finalOrder').on('click',function (){
    finalOrder(data);
})

